package com.xhwl.data.service.impl.personal;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhwl.common.pojo.cent.sdata.personnel.StaffOrganization;
import com.xhwl.data.dao.personal.IStaffOrganizationDao;
import com.xhwl.data.pojo.OrganizationStaffCount;
import com.xhwl.data.service.personal.IStaffOrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Author: luyi
 * @Description:
 * @Date: Create in 15:59 2022/2/8
 */
@Service
public class StaffOrganizationServiceImpl extends ServiceImpl<IStaffOrganizationDao, StaffOrganization> implements IStaffOrganizationService {

    @Autowired
    private IStaffOrganizationDao staffOrganizationDao;

    @Override
    public List<OrganizationStaffCount> countOrg(List<Integer> organizationIds) {
        if(organizationIds.isEmpty()){
            return Collections.emptyList();
        }
        return staffOrganizationDao.countOrg(organizationIds);
    }

    /**
     * 根据企业ID查找StaffOrganization
     */
    @Override
    public StaffOrganization findStaffOrganizationByEnterpriseId(Integer enterpriseId) {
        QueryWrapper<StaffOrganization> enterprise_id = new QueryWrapper<StaffOrganization>().eq("enterprise_id", enterpriseId).last("limit 1");
        return getBaseMapper().selectOne(enterprise_id);
    }
}
